<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            托码校验
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">扫描托码</div>
                    <input type="text" class="aui-input" placeholder="请扫描托码" style="width: 80%;" id="trayyinfoid" onclick="getIdSelector();"onfocus="focusFn(this)">
                    <i class="aui-input-addon aui-iconfont aui-icon-scan " style="font-size: 1.6rem" onclick="toScanner(1);"></i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">零件储存卡</div>
                    <input type="text" class="aui-input" placeholder="请扫描零件储存卡" style="width: 80%;" id="ljcck" onclick="getIdSelector();"onfocus="focusFn(this)">
                    <i class="aui-input-addon aui-iconfont aui-icon-scan " style="font-size: 1.6rem" onclick="toScanner(2);"></i>
                </div>
            </li>
        </ul>
        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="save()">校验</div>
        <ul class="ui-selectee" id="tbodyHtml">


        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    var scanRule = ""; //条码解析规则


    //初始化查询仓库下拉框
    apiready = function() {

        $("#trayyinfoid").focus();

    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        $("#" + el.id).select();
    }

   //初始化
   apiready = function() {

   $("#trayyinfoid").focus();
   idSelector = "trayyinfoid";
//    $("#ljcck").select();
}



    //扫描条码
    function toScanner(flag) {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function(ret, err) {

            var sm = ret;
            //托码
            if (flag == 1) {
                var text = document.getElementById("trayyinfoid");
                text.value = sm;
                $("#ljcck").focus();
                save()
                //条码
            } else {

                var text = document.getElementById("ljcck");
                text.value = sm;
                save()
            }
        });
    }

    //零件存储卡监听回车事件
    $("#ljcck").on('keypress', function(e) {
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            $("#ljcck").val("");
            $("#ljcck").val(tm);
            tmjy(tm,"#ljcck");
            // save()
        }
    });

    //托码监听回车事件
    $("#trayyinfoid").on('keypress', function(e) {
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            $("#trayyinfoid").val("");
            $("#trayyinfoid").val(tm);
            tmjy(tm,"#trayyinfoid");
            // $("#ljcck").focus();
            // save()
        }
    });
    function tmjy(code,input){
        var serverUrl = localStorage.getItem('serverUrl');
        var un = localStorage.getItem("un");
        var url = serverUrl + "/app/getSelectTrayyinfoid";
        var data = {
            values: {
                un: un,
                appVersion: api.appVersion,
                trayyinfoid : code
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    if(input == "#ljcck"){
                        save()
                    }else if(input == "#trayyinfoid"){
                        $("#ljcck").focus();
                        save()
                    }
                } else {
                    $(input).val("");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }
    function save(){

        var ljcck = $("#ljcck").val();
        var trayyinfoid = $("#trayyinfoid").val();
        var color = "";
        var str = "";
        if (ljcck != null && ljcck != undefined && ljcck != ""
                &&trayyinfoid != null && trayyinfoid != undefined && trayyinfoid != "") {
                    if(ljcck == trayyinfoid){
                        color = "#9ACD32";
                        str = "tg.png"
                    }else{
                        color = "#FF0000";
                        str = "btg.png"
                    }
                    var html = "";
                    html += "<li class='sortable ui-selectee ui-sortable'>";

                        //html += "<div class='aui-list-item-text ui-selectee' style='width:100%;height: 80px; background-color:" + color + "'>";
                        html += "<div class='aui-list-item-text ui-selectee' style='width:100%;margin-top:70px; margin-left:49px;'>"
                        //html += "<div class='aui-list-item-inner ui-selectee'>";
                        //html += "<div class='aui-list-item-text ui-selectee' style='height: 90px; background-color:" + color + "'>";
                        //html += "<div class='aui-list-item-label ui-selectee list-tr-title'>";
                        //html += "<table border align='center'   style='border:none'  >"
                        //html += "<tr   style='border:none'>"
                        //html += "<td align='center' style='border:none'><font size='6' color='black' >"
                        html +=  "<img src='../image/" + str + "' width='280' hight='280' />"
                        //html += "</font></td>"
                        //html += "</tr>" 
                        //html += "</table>";
                        html += "</div>";
                       // html += "</div>";
                        //html += "</div>";

                        html += "</li>";
                        console.log(html)
                    $api.html($api.byId("tbodyHtml"), html);
        }
    }


    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
    function focusFn(ele){
        $api.attr(ele,'readonly', 'readonly');
            setTimeout(() => {
            $api.removeAttr(ele,'readonly');
            }, 200);
        };
</script>

</html>
